//准备函数
jQuery(document).ready(function() {

    //区域经理fieldid
    var  qyjlField=WfForm.convertFieldNameToId("xm", "detail_1");

    //分公司fieldid
    var fgsField=WfForm.convertFieldNameToId("fgs");
    //crm平均分
    var crmField=WfForm.convertFieldNameToId("crm","detail_1");
    //服务标准执行
    var fwbzAField=WfForm.convertFieldNameToId("fwbzA","detail_1");
     var fwbzBField=WfForm.convertFieldNameToId("fwbzB","detail_1");
     var fwbzCField=WfForm.convertFieldNameToId("fwbzC","detail_1");
     //陈列管理
     var clglAField=WfForm.convertFieldNameToId("clglA","detail_1");
      var clglBField=WfForm.convertFieldNameToId("clglB","detail_1");
       var clglCField=WfForm.convertFieldNameToId("clglC","detail_1");
    //存放区域经理姓名
    var qyjlName;
    //存放区域经理姓名集合
    var qyjlNames;


        //获取明细表1的fieldid
       // var subData = jQuery("#submitdtlid0").val();
      var subData=WfForm.getDetailAllRowIndexStr("detail_1");
        //获取主表分公司的值
        var mainCompany =WfForm.getFieldValue(fgsField);

        //判断是否为null
        if (subData != null) {
            //split 分组
            var arr = subData.split(",");
            //循环判断获取区域经理姓名的数据
            for (var num = 0; num < arr.length; num++) {
                qyjlName = WfForm.getFieldValue(qyjlField + "_" + arr[num]);

                if (qyjlName!=null&&qyjlName!="undefined") {
                qyjlNames = qyjlNames + ","+qyjlName;
            }
            }

        }

        //ajax传值并根据返回值给表单字段赋值
        jQuery.ajax({
            url: "/api/weavernorth/action/performance/HandlerPerformance/getDatas",
            data: {
                "qyjlNames": qyjlNames,
                "mainCompany": mainCompany
            },
            dataType: "json",
            //异步
            async: false,
            success: function (data) {
            //console.log(data);
            //对应表单字段赋值

                for (var num = 0; num < arr.length; num++) {
                	WfForm.changeFieldValue(crmField+"_"+arr[num], {value: data.CRMALLScore });

                	WfForm.changeFieldValue(fwbzAField+"_"+arr[num], {value: data.FwbzA });
                	WfForm.changeFieldValue(fwbzBField+"_"+arr[num], {value: data.FwbzB });
                	WfForm.changeFieldValue(fwbzCField+"_"+arr[num], {value: data.FwbzC });
                	WfForm.changeFieldValue(clglAField+"_"+arr[num], {value: data.ClglA });
                	WfForm.changeFieldValue(clglBField+"_"+arr[num], {value: data.ClglB });
                	WfForm.changeFieldValue(clglCField+"_"+arr[num], {value: data.ClglC });
//                    jQuery("#field8170_"+arr[num]).val(data.CRMALLScore);
//                    jQuery("#field9901_"+arr[num]).val(data.FwbzA);
//                    jQuery("#field9902_"+arr[num]).val(data.FwbzB);
//                    jQuery("#field9903_"+arr[num]).val(data.FwbzC);
//                    jQuery("#field9906_"+arr[num]).val(data.ClglA);
//                    jQuery("#field9907_"+arr[num]).val(data.ClglB);
//                    jQuery("#field9908_"+arr[num]).val(data.ClglC);
                }


            },
            error: function (data) {  //请求失败时被调用的函数
                alert("加载失败，请联系管理员！")
            }
        })









})

